package cn.lucky.springcloud.controller;

import cn.lucky.springcloud.service.HystrixPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author lingpeng.jiang
 * @create 2020-12-28-22:25
 */
@RestController
@RequestMapping("/hystrix/payment")
@Slf4j
public class HystrixPaymentController {

    @Resource
    private HystrixPaymentService hystrixPaymentService;

    @Value("${server.port}")
    private String serverPort;

    /**
     * 正常访问
     * @param id
     * @return
     */
    @GetMapping("/ok/{id}")
    public String hystrixPaymentInfo_OK(@PathVariable("id") Integer id){
        String s = hystrixPaymentService.hystrixPaymentInfo_OK(id);
        log.info("请求成功: " + s);
        return s;
    }

    /**
     * 超时访问
     * @param id
     * @return
     */
    @GetMapping("/timeout/{id}")
    public String hystrixPaymentInfo_Timeout(@PathVariable("id") Integer id){
        String s = hystrixPaymentService.hystrixPaymentInfo_Timeout(id);
        log.info("请求成功: " + s);
        return s;
    }


    /**
     * 测试熔断
     * @param id
     * @return
     */
    @GetMapping("/circuit/{id}")
    public String circuitBreaker(@PathVariable("id") Integer id){
        return hystrixPaymentService.circuitBreaker(id);
    }



    @GetMapping("/serverPort")
    public String getServerPort(){
        return serverPort;
    }
}
